package com.hotau.account.mode.balance;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hotau.R;

/**
 * 收支汇总Mode适配器
 * @author liujia (liujia9234@126.com)
 * @data @2011-12-11
 * @version 1.0
 * <ul>
 * 		<li>1.0 创建</li>
 * </ul>
 */
public class DetailAdapter extends BaseAdapter {

	private List<BalanceEntity> data = new ArrayList<BalanceEntity>();
	
	private Context ctx;
	private LayoutInflater mInflater;
	
	public DetailAdapter(Context context ) {
		ctx = context;
		mInflater = LayoutInflater.from(ctx);
	}
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Object obj = getItem(position);
		final LinearLayout layout = new LinearLayout(ctx);
		LayoutInflater vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(obj instanceof BalanceEntity){
			BalanceEntity entiey = (BalanceEntity) obj;
			vi.inflate(R.layout.account_balance_list, layout,true);
			((TextView)layout.findViewById(R.id.account_list_tv_createdate)).setText(entiey.getCreateDate());
			TextView tv_type = ((TextView)layout.findViewById(R.id.account_list_tv_type));
//			tv_type.getPaint().setFakeBoldText(true);
//			if("100".equals(entiey.getTradeType())){
//				tv_type.setText(ctx.getResources().getTextArray(R.array.order_trade_type_text)[0]);
//			}else if("101".equals(entiey.getTradeType())){
//				tv_type.setText(ctx.getResources().getTextArray(R.array.order_trade_type_text)[1]);
//			}
			tv_type.setText(entiey.getTradeType());
			TextView amount_tv = (TextView)layout.findViewById(R.id.account_list_tv_amount);
			if("1".equals(entiey.getType())){
				amount_tv.setTextColor(ctx.getResources().getColor(R.color.green));
				amount_tv.setText("+ ￥ "+entiey.getAmount());
			}else if("2".equals(entiey.getType())){
				amount_tv.setTextColor(ctx.getResources().getColor(R.color.orange));
				amount_tv.setText("- ￥ "+entiey.getAmount());
			}
		}
		return layout;
	}
	
	/**
	 * 增加数据
	 * @param name
	 * @param date
	 * @param text
	 */
	@SuppressWarnings("unchecked")
	public void addItem(BalanceEntity entiey ){
		data.add(entiey);
	}
	
	public void clearData(){
		data.clear();
	}

}
